var express = require('express');
var path = require('path');
var logger = require('morgan');
//引入跨域
let cors = require('cors')
//引入md5加密模块
const md5 = require('md5')
console.log(md5('123344'));
//引入session模块
const cookieSession = require('cookie-session')



//引入首页
var indexRouter = require('./routes/index');
//引入登录注册
var userInfoRouter = require('./routes/userInfo');
//引入在线课程
let online = require('./routes/online')
//引入课程视频详情
let videoDetail = require('./routes/viedoDetail')
//引入视频播放页
let videoPlay = require('./routes/videoPlay')
//引入个人中心
let personContent = require('./routes/personContent')
//使用express
var app = express();
//跨域
app.use(cors())


app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
//使用密钥
cookieSession({
  keys:['jesiduhfiesfg','dioshi']
})
app.use(logger('dev'));
//接收post参数
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
//开放静态资源
app.use('/uploads',express.static(path.join(__dirname, 'uploads')));
//使用首页
app.use('/', indexRouter);
//使用登录注册
app.use(userInfoRouter);
//使用在线课程
app.use(online);
//使用课程视频详情
app.use(videoDetail);
// 使用视频播放页
app.use(videoPlay);
//使用个人中心
app.use(personContent);



app.use(function(req, res, next) {
  res.status(404)
  res.send({
    msg:'404了',
    status:404
  })
});


app.use(function(err, req, res, next) {
  res.status(500);
  err.status = 500
  res.send(err);
});

module.exports = app;
